import connection from '../app/database.js';

export async function create(user){
    const  {username, password} = user;
    const sql = `INSERT INTO users (name, password) VALUES(?, ?);`;
    return await connection.execute(sql, [username, password])
}

export async function getUserByName(name){
    const sql = `SELECT id from users WHERE name = ?;`;
    const result =  await connection.execute(sql, [name])
    return result[0]
}

export async function updateAvatar(avatar, userId){
    const statement = `
            UPDATE users SET avatar = ? WHERE id = ?;
        `;
    const [result] = await connection.execute(statement, [avatar, userId]);
    return result
}